<?php
session_start();

$error = false;

if((!isset($_SESSION["user"]))||(!isset($_SESSION["type"])))
	$error = true;

if(($_SESSION["type"] != "admin")||($_SESSION["user"] == ""))
	$error = true;

if($error)
{
	session_unset();
	session_destroy();

	header("Location: login.php");
	exit;
}

$utente = $_SESSION["user"];

$azione = @$_GET["action"];
$fname = @$_GET["fname"];

if($azione == "del")
{
	if(file_exists("upload/$fname"))
		unlink("upload/$fname");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style type="text/css" media="print">
TD {font-size:11px; font-family="arial,helvetica"}
P {text-indent:-10; text-align="justify"; margin-left:10;}
A:link {color: #44aaaa; text-decoration: underline;}
A:active {color: #000000; text-decoration: underline;}
A:visited {color: #227788; text-decoration: underline;}
A:hover {color: #000000; text-decoration: none; }
BODY {font-size:12px; font-family="arial,helvetica";}
FORM {margin-top:5}
</style>
<style type="text/css" media="screen">
TD {font-size:13px}
P {text-indent:-10; text-align="justify"; margin-left:10;}
A:link {color: #44aaaa; text-decoration: underline;}
A:active {color: #000000; text-decoration: underline;}
A:visited {color: #227788; text-decoration: underline;}
A:hover {color: #000000; text-decoration: none;}
BODY {background-image: url(images/captext.gif); font-size:14px}
FORM {margin-top:5}
</style>
</head>

<body>
<center>
<font color="#228888" size="4">
	<br><br><b>BACHECA: GESTIONE FILE<br><br>Benvenuto <?php echo "<em>$utente</em>"; ?></b><br><br>
</font>
</center>
<center>
<?php

$flist = Array();

if(file_exists("upload/"))
{
	$handle = opendir("upload/");
	
	while(false !== ($file = readdir($handle)))
	{ 
		if(is_file("upload/$file"))
		{
			if($file != "index.html")
				array_push($flist, $file);
		}
	}
	
	$handle = closedir($handle);
	
	sort($flist);
}
else
	echo "<span style=\"text-align: center; font-weight: bold; color: black;\">Non ci sono file nel server.</span>";

if(count($flist) > 0)
{
	foreach($flist as $value)
	{
		echo "<table style=\"table-layout: fixed; width:90%; margin-left: auto; margin-right: auto;\">
			  <tr bgcolor=\"#FFDFBF\">
			  	<td style=\"text-align: center;\" width=\"40px\">
					<a href=\"gest_file.php?action=del&fname=$value\" title=\"Elimina\" onclick=\"javascript: return(confirm('Eliminare il file selezionato?'))\"><img src=\"images/msg_del.png\" alt=\"Elimina\" style=\"border: 0px;\" width=\"14px\" height=\"14px\"></a>
					<a href=\"upload/$value\" title=\"Visualizza\" target=\"_blank\"><img src=\"images/file_view.png\" alt=\"Visualizza\" style=\"border: 0px;\" width=\"14px\" height=\"14px\"></a>
				</td>
				<td width=\"380px\"><b>Nome File:</b> $value</td>
				<td width=\"150px\"><b>Dimensione:</b> " . round((@filesize("upload/$value") / 1024), 2) . " Kb</td>
				<td><b>Ultima Modifica:</b> " . date("d/m/Y - H:i:s", filectime("upload/$value")) . "</td>
				<td><b>Ultima Lettura:</b> " . date("d/m/Y - H:i:s", fileatime("upload/$value")) . "</td>
			  </tr>
			  </table>";
	}
}
else
	echo "<span style=\"text-align: center; font-weight: bold; color: black;\">Non ci sono file nel server.</span>";
?>
<br><br><a href="admin_opt.php">Torna Indietro</a><br><br>
</center>
<table bgcolor="#88CCCC" border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
	<td> Ultima modifica: <?php echo date("d/m/Y");?></td>
	<td align="right"> Approvato da: Presidente CCdL</td>
</tr>
</table>
</body>
</html>